/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package struts;

import Service.EventService;
import Service.EventServiceImpl;
import Service.PlanService;
import Service.PlanServiceImpl;
import java.util.*;
import net.sf.json.JSONObject;
import javabeans.*;


/**
 *
 * @author zhi
 */
public class TestJason {
    public static void main(String[] args) {
        TestJ test = new TestJ();
        //test.test1();
        test.testDeleteEvent();
        //test.jsonToObjectTest();
    }    
}

class TestJ {
    public void test1() {
        Plan plan = new Plan();
        plan.setPlanid(123);
        plan.setPlanname("plan1");
        plan.setPlandescript("my plan");
        Event event1 = new Event();
        event1.setId(1001);
        //event1.setColor(Color.yellow);
        event1.setEventname("event1");
        event1.setEventdescript("my event1");
        event1.setEventtime("123");
        event1.setType("hotel");
        event1.setColor("red");
        event1.setEventdate("asdasd");
        event1.setPointX(1.212);
        event1.setPointY(121212.333);
        //event1.setPointonmap(new Point(12,123));
        //event1.setEventendtime(new Date());
        Event event2 = new Event();
        event2.setId(1002);
        event2.setColor("green");
        event2.setEventname("event2");
        event2.setEventdescript("my event2");
        //event2.setEventstarttime(new Date());
        //event2.setEventendtime(new Date());
        List<Event> events = new ArrayList<Event>();
        events.add(event1);
        events.add(event2);
        plan.setEvents(events);


        //Object To Json
        JSONObject jsonObject = JSONObject.fromObject(plan);
        System.out.println(jsonObject);

        //Json to Object
        Plan plan2 =(Plan) JSONObject.toBean(jsonObject,Plan.class);
        System.out.println(plan2.getPlanid()+"   ");
        JSONObject jsonObject2 = JSONObject.fromObject(plan2);
        System.out.println(jsonObject2);
    }


    public void test2() {
        String str = "{\"planid\":35,\"planname\":\"asd\",\"plandescript\":\"asd\",\"eventInfos\":[{\"operation\":\"new\",\"event\":{\"id\":\"\",\"eventname\":\"1111\",\"type\":\"12\",\"pointX\":\"121\",\"pointY\":\"212\",\"eventdate\":\"12/01/2009\",\"eventtime\":\"3:15 AM\",\"color\":\"1212\",\"eventdescript\":\"1212\"}}]}";

        JSONObject jsonObject = JSONObject.fromObject(str);
        Map <String, Class> m = new HashMap <String, Class>();
        m.put("eventInfos", EventInfo.class);
        m.put("event", Event.class);
        PlanInfo planInfo = (PlanInfo) JSONObject.toBean(jsonObject, PlanInfo.class, m);
        List<EventInfo> list = planInfo.getEventInfos();
        String o = list.get(0).getOperation();
        System.out.println(o);
        planInfo.saveThisPlan();
    }

    public void testDeleteEvent() {
        int eventid = 2;
        int planid = 2;
        //PlanService ps = new PlanServiceImpl();
        EventService es = new EventServiceImpl();
        es.deleteEvent(eventid, planid);

    }


}


